package com.own.core.html.form.dateField;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.wicket.datetime.PatternDateConverter;
 
import org.apache.wicket.util.string.Strings;

import com.own.core.util.OwnDate;

/**
 * Converts from and to URLs.
 * 
 * @author Eelco Hillenius
 */

public class OwnDateConverter extends PatternDateConverter {
	public OwnDateConverter(String datePattern, boolean applyTimeZoneDifference) {
		super(datePattern, applyTimeZoneDifference);
	}

	private static final long serialVersionUID = 1L;

	/**
	 * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String,Locale)
	 */
	@Override
	public OwnDate convertToObject(final String value, Locale locale) {
	Date date=	(Date) super.convertToObject(value, locale);
		if (date== null) {
			return null;
		}
		return new OwnDate(date);
	}

	/**
	 * @see org.apache.wicket.util.convert.converters.DateConverter#convertToObject(java.lang.String,
	 *      java.util.Locale)
	 */
 

	/**
	 * @param locale
	 * @return Returns the date format.
	 */
	public DateFormat getDateFormat(Locale locale) {
		if (locale == null) {
			locale = Locale.getDefault();
		}

		return DateFormat.getDateInstance(DateFormat.SHORT, locale);
	}

}
